package com.yxj_01;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class iteratorDemo01 {
    public static void main(String[] args) {
        Collection<String> c = new ArrayList<String>();

        c.add("world");
        c.add("hello");
        c.add("123" );
        //Iterator<E> iterator();返回集合中元素的迭代器，通过集合的iterator()方法得到
        Iterator<String> it = c.iterator();
        //E next();返回迭代中的下一个元素
        //System.out.println(it.next());
        //System.out.println(it.next());
        //boolean hasNext();如果迭代器有更多元素，则返回true
        while(it.hasNext()) {
            //System.out.println(it.next());
            String s = it.next();
            System.out.println(s);
        }

    }
}
